package com.bj58.mis.apm.server.core.util;

import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.KeySpec;

public class MD5 {

    private static final byte[] salt = "apm".getBytes();

    public static String encode(String... strs){
        if(strs.length == 0){
            return null;
        }
        StringBuffer sb = new StringBuffer(32);

        byte[] bt = toString(strs).getBytes();
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");

            byte[] array = md.digest(bt);
            for (int i = 0; i < array.length; i++) {
                sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).toUpperCase().substring(1, 3));
            }
        } catch (Exception e) {
            return null;
        }

        return sb.toString();
    }

    private static String toString(String... strs){
        StringBuilder sb = new StringBuilder();
        for(String s : strs){
            sb.append(s);
        }
        return sb.toString();
    }

//    public static void main(String[] args){
//        System.out.println(encode("12345").length());
//        System.out.println(encode("12345","select * from aaaa"));
//        System.out.println(encode("12345","select * from aaaa","salt"));
//        System.out.println(encode());
//    }
}
